//
//  HR_AlbumListTableViewCell.m
//  HR_PickKit
//
//  Created by KK on 2017/7/21.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HR_AlbumListTableViewCell.h"
#import "HR_AlbumListModel.h"
#import "HR_Macro.h"

@interface HR_AlbumListTableViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *albumImageView;
@property (weak, nonatomic) IBOutlet UILabel *alubumTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *alubumCountLab;


@property (strong, nonatomic) PHCachingImageManager *imageManager;
@end

@implementation HR_AlbumListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateAlbumImage:(PHFetchResult *)fetchResult titleName:(NSString *)name{
    if (fetchResult.count>0) {
        WEAK(weakSelf);
        PHAsset *asset = fetchResult[fetchResult.count-1];
        [self.imageManager requestImageForAsset:asset targetSize:CGSizeMake(self.bounds.size.height, self.bounds.size.height) contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
            weakSelf.albumImageView.image = result;
        }];
    }
    self.alubumTitleLab.text = name;
    self.alubumCountLab.text = [NSString stringWithFormat:@" (%ld) ",fetchResult.count];
}

- (PHCachingImageManager *)imageManager {
    if (!_imageManager) {
        _imageManager = [[PHCachingImageManager alloc] init];
    }
    return _imageManager;
}
@end
